package mx.netbrain.bean;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import mx.netbrain.dao.StorageDao;
import mx.netbrain.dao.impl.StorageDaoImpl;
import mx.netbrain.model.Status;
import mx.netbrain.model.Storage;

public class StorageBean {

	private String name;
	private String route;
	private BigDecimal space;
	private Boolean shared;
	private List<Storage> listStorage;
	private Storage storage = new Storage();
	private Status status = new Status();

	public StorageBean() {

	}

	public void saveStorage() {
		storage.setName(name);
		storage.setRoute(route);
		storage.setSpace(space);
		storage.setShare(shared);
		storage.setRegister(new Date());
		status.setId(1);
		storage.setStatus(status);
		StorageDao storageDao = new StorageDaoImpl();
		storageDao.save(storage);
		storage = new Storage();
		name = new String();
		route = new String();
		space = null;
		shared = null;
	}

	public void prepareStorage(Integer id) {
		StorageDao storageDao = new StorageDaoImpl();
		storage = storageDao.findById(id);
		name = storage.getName();
		route = storage.getRoute();
		space = storage.getSpace();
		shared = storage.getShare();
	}

	public void editStorage() {
		storage.setName(name);
		storage.setRoute(route);
		storage.setSpace(space);
		storage.setShare(shared);
		StorageDao storageDao = new StorageDaoImpl();
		storageDao.update(storage);
	}

	public void deleteStorage() {
		status.setId(2);
		storage.setStatus(status);
		StorageDao storageDao = new StorageDaoImpl();
		storageDao.delete(storage);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRoute() {
		return route;
	}

	public void setRoute(String route) {
		this.route = route;
	}

	public BigDecimal getSpace() {
		return space;
	}

	public void setSpace(BigDecimal space) {
		this.space = space;
	}

	public Boolean getShared() {
		return shared;
	}

	public void setShared(Boolean shared) {
		this.shared = shared;
	}

	public List<Storage> getListStorage() {
		StorageDao storageDao = new StorageDaoImpl();
		listStorage = storageDao.listAll();
		return listStorage;
	}

	public void setListStorage(List<Storage> listStorage) {
		this.listStorage = listStorage;
	}

}
